package com.leyou.cart.mq;

import com.leyou.cart.service.CartService;
import com.leyou.common.constants.MQConstants;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * RabbitMQ监听器
 */
@Component
public class MQListener {

    @Autowired
    private CartService cartService;

    /**
     * 下单后购物车清除对于商品
     * @param mqMap
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = MQConstants.Queue.CART_CLEAR_QUEUE , durable = "true"),
            exchange = @Exchange(value = MQConstants.Exchange.CART_EXCHANGE_NAME, type = ExchangeTypes.TOPIC),
            key = MQConstants.RoutingKey.CART_CLEAR_KEY
    ))
    public void cartClear(HashMap<String , Object> mqMap){
        cartService.cartClear(mqMap);
    }

}
